<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>call&apply</title>
</head>
<body>

	<script>
		/**
		 * 改变this指向
		 */

		var obj = {
			name: 'call',
			getName: function() {
				console.log(this.name)
			}
		};

		var bar = {
			name : "foo"
		}
		obj.getName.call(bar) //fooo 如果bar是一个function的话就会把bar这个函数打印在控制台上
		
		var test = function() {
			console.log(this)
		}
		test.call(null) //true
		test.call(bar) //false



		/**
		 * 实现继承
		*/

		function Foo(name){

		 	this.name = name;
		 	this.showName = function() {
		 		console.log(this.name)
		 	}

		}

		function Bar(name) {
			Foo.call(this,name)
		}
		var bar = new Bar('foo');
		bar.showName();


	</script>
	
</body>
</html>